package com.sh.rbac.core.common.enums;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;

import java.util.stream.Stream;

/**
 * 状态枚举
 *
 * @author wb
 * @since 2024-07-14
 */

@Schema(description = "状态枚举")
@Getter
public enum StatusEnum {
    DEFAULT(-1, null),
    NORMAL(0, "正常"),
    DISABLE(1, "停用");

    @Schema(description = "状态码")
    private final Integer code;

    @Schema(description = "状态描述")
    private final String desc;

    StatusEnum(Integer code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    // 根据 code 获取 desc
    public static String getDescByCode(Integer code) {
        return Stream.of(values())
                .filter(bean -> bean.code.equals(code))
                .findAny()
                .orElse(DEFAULT)
                .getDesc();
    }
}
